package org.genew.squadra.xml.model.builder;

import java.util.ArrayList;
import java.util.List;

import org.genew.squadra.xml.model.MyForm;
import org.genew.squadra.xml.model.OrdinamentoXHTML;
import org.genew.squadra.xml.model.content.manifest.Item;
import org.genew.squadra.xml.model.content.manifest.Manifest;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

@Component
public class ManifestBuilderFromForm {
	

//	public static Manifest build (CommonsMultipartFile[] filesXHTML, CommonsMultipartFile[] filesCSS,CommonsMultipartFile[] filesIMG){
//		
//		List<Item> lstItm = new ArrayList<>();
//		
//		//lstItm.addAll(buildXHTML(filesXHTML)); //RIVEDERE
//		lstItm.addAll(buildCSS(filesCSS));
//		lstItm.addAll(buildIMG(filesIMG));
//		
//		 Manifest mnf = new Manifest("Prova", lstItm);
//	
//		return mnf;
//	}
	
//	public static List<Item>  buildXHTML (CommonsMultipartFile[] filesXHTML){
//		 List<Item> lst = new ArrayList<Item>();
//		  Item temp = new Item();
//		for(int i=0;i<filesXHTML.length;i++){
//			temp.setId(filesXHTML[i].getOriginalFilename().replace(".xhtml", ""));//id
//			temp.setHref(filesXHTML[i].getOriginalFilename());//HREF
//			temp.setMedia_type("application/xhtml+xml");//MEDIATYPE
//			lst.add(temp);
//			
//		}
//		for(int i=0;i<lst.size();i++){
//		System.out.println("*********"+lst.get(i).getHref());
//		}
//		return  lst; 
//	}
	
	public static List<Item>  buildCSS (CommonsMultipartFile[] filesCSS){
		 List<Item> lstItm = new ArrayList<>();
		  Item temp = new Item();
		for(int i=0;i<filesCSS.length;i++){
			//temp.setId(filesCSS[i].getOriginalFilename().replace(".css", ""));//id
			temp.setId(filesCSS[i].getOriginalFilename().replace(".css", ""));//id
			temp.setHref(filesCSS[i].getOriginalFilename());//HREF
			temp.setMedia_type("text/css");//MEDIATYPE
			lstItm.add(temp);
		}
		
		return  lstItm; 
	}
	
	public static List<Item>  buildIMG (CommonsMultipartFile[] filesIMG){
		 List<Item> lstItm = new ArrayList<>();
		  Item temp = new Item();
		for(int i=0;i<filesIMG.length;i++){
			temp.setId(filesIMG[i].getOriginalFilename().replace(".jpg", ""));//id
			temp.setHref(filesIMG[i].getOriginalFilename());//HREF
			temp.setMedia_type("image/jpeg");//MEDIATYPE
			lstItm.add(temp);
		}
		
		return  lstItm; 
	}

}
